﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Localization.Settings;
using UnityEngine.UI;

namespace UI
{
    public class LocaleSelectorUi : MonoBehaviour
    {
        [SerializeField] private Button[] buttons;
        
        
        private IEnumerator Start()
        {
            foreach (Button button in buttons)
            {
                button.interactable = false;
            }
            
            // Wait for the localization system to initialize
            yield return LocalizationSettings.InitializationOperation;

            for (int i = 0; i < buttons.Length; i++)
            {
                int index = i;
                buttons[i].onClick.AddListener(() => SelectLocale(index));
                buttons[i].interactable = true;
            }
        }

        private void SelectLocale(int index)
        {
            LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[index];
        }
    }
}